class Solution {
public:
    int strStr(string haystack, string needle) {
        if(haystack == needle)
        {
            return 0;
        }
        int num = needle.size();
        int length = haystack.size();
        for(int i = 0; i < length - num+1; i++)
        {
            std::string sub_string = haystack.substr(i, num);
            if(sub_string == needle)
            {
                return i;
            }
        }
        return -1;
    }
};

class Solution:
    def strStr(self, haystack: str, needle: str) -> int:
        if haystack == needle:
            return 0
        l1 = len(haystack)
        l2 = len(needle)
        for i in range(l1 - l2 + 1):
            if haystack[i:i+l2] == needle:
                return i
        return -1